import os
import platform
import subprocess

def build_executable():
    """构建可执行文件"""
    print("开始构建可执行文件...")
    
    # 检查是否安装了PyInstaller
    try:
        import PyInstaller
        print("PyInstaller已安装")
    except ImportError:
        print("安装PyInstaller...")
        subprocess.check_call(["pip", "install", "pyinstaller"])
    
    # 构建命令
    cmd = [
        "pyinstaller",
        "--name=多项式拟合工具",
        "--onefile",
        "--windowed",
        "--clean",
        "--add-data=sample_data.csv;.",  # Windows使用分号分隔
        "main.py"
    ]
    
    # 在Linux和macOS上使用冒号作为分隔符
    if platform.system() != "Windows":
        cmd[5] = "--add-data=sample_data.csv:."
    
    # 执行构建
    subprocess.check_call(cmd)
    
    print("构建完成！")
    print(f"可执行文件位于: {os.path.join('dist', '多项式拟合工具')}")

if __name__ == "__main__":
    build_executable() 